package cn.itcast.cxf.ws.client;

import cn.itcast.cxf.service.Car;
import cn.itcast.cxf.service.IUserService;
import cn.itcast.cxf.service.User;
import cn.itcast.cxf.service.UserService;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import java.util.List;

/**
 * Created by Think on 2017/9/18.
 */
public class WS_Client {
    //调用JDK发布的
//    public static void main(String[] args) {
//        //根据使用说明书
//        UserService userServiceImpl = new UserService();
//        IUserService userService = userServiceImpl.getUserServiceImplPort();
//        System.out.println(userService.sayHello("张杰"));
//        User user = new User();
//        user.setUsername("xiaoming");
//        List<Car> cars = userService.findCarsByUser(user);
//        System.out.println(cars);
//    }

    /**使用CXF的方式去调用*/
    public static void main(String[] args) {
        //根据使用说明书
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
        // 表示指定了接口
        jaxWsProxyFactoryBean.setServiceClass(IUserService.class);
        // 指定地址（webservice的使用说明书地址）
        jaxWsProxyFactoryBean.setAddress("http://localhost:9999/userService?wsdl");
        // 返回指定的接口
        IUserService userService = (IUserService) jaxWsProxyFactoryBean.create();   //最终都是为了获取此接口,要用的方法都在此接口
        System.out.println(userService.sayHello("张杰"));
        User user = new User();
        user.setUsername("xiaoming");
        List<Car> cars = userService.findCarsByUser(user);
        System.out.println(cars);
    }
}
